package com.cxx.purchasecharge.core.model.persistence;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.cxx.purchasecharge.core.model.BaseModel;
import com.cxx.purchasecharge.core.model.OrderStatusCode;
import com.cxx.purchasecharge.core.model.OrderTypeCode;

/**
 * 账单
 */
@Entity
@Table (name = "pc_order")
public class Order extends BaseModel
{
    private static final long serialVersionUID = 1L;

    private long id;

    private Customer customer;
    private Contact contact;
    private List <OrderItem> orderItems;
    /**
     * 交易额
     */
    private float dealMoney;
    /**
     * 折扣率
     */
    private float discount;
    /**
     * 应收款
     */
    private float receivable;
    /**
     * 实收额
     */
    private float paidMoney;
    /**
     * 利润
     */
    private float profit;

    /**
     * 最后付款日期
     */
    private Date payDate;
    /**
     * 账期
     */
    private int payDays = 30;

    /**
     * 业务员
     */
    private long userSigned;
    /**
     * 操作员
     */
    private long userOperatedBy;
    private long userCreatedBy;
    private long userUpdatedBy;
    private String comment;
    private Date createDate = new Date ();
    private Date lastUpdated;
    /**
     * 发货时间
     */
    private Date shipDate;

    /**
     * 物流单号
     */
    private String logisticsNumber;

    /**
     * 是否开发票
     */
    private boolean isInvoiced = false;
    /**
     * 是否发货
     */
    private boolean isShipped = false;
    /**
     * 网络电商订单号
     */
    private String networkOrderId;

    private OrderStatusCode statusCode = OrderStatusCode.NEW;
    private OrderTypeCode typeCode;
    private Receiver receiver;

    private long project;
    
    public Order () {}

    @Id
    public long getId ()
    {
        return id;
    }

    public void setId (long id)
    {
        this.id = id;
    }

    @OneToMany (mappedBy = "order", cascade =
    { CascadeType.ALL })
    public List <OrderItem> getOrderItems ()
    {
        return orderItems;
    }

    public void setOrderItems (List <OrderItem> orderItems)
    {
        this.orderItems = orderItems;
        if (null != orderItems)
        {
            for (OrderItem orderItem : orderItems)
            {
                orderItem.setOrder (this);
            }
        }
    }

    @Column (nullable = false)
    public float getDealMoney ()
    {
        return dealMoney;
    }

    public void setDealMoney (float dealMoney)
    {
        this.dealMoney = dealMoney;
    }

    public float getPaidMoney ()
    {
        return paidMoney;
    }

    public void setPaidMoney (float paidMoney)
    {
        this.paidMoney = paidMoney;
    }

    public float getProfit ()
    {
        return profit;
    }

    public void setProfit (float profit)
    {
        this.profit = profit;
    }

    @Column (nullable = false)
    public Date getPayDate ()
    {
        return payDate;
    }

    public void setPayDate (Date payDate)
    {
        this.payDate = payDate;
    }

    @Column (nullable = false)
    public int getPayDays ()
    {
        return payDays;
    }

    public void setPayDays (int payDays)
    {
        this.payDays = payDays;
    }

    @Column (nullable = false)
    public long getUserSigned ()
    {
        return userSigned;
    }

    public void setUserSigned (long userSigned)
    {
        this.userSigned = userSigned;
    }

    @Column (length = 1024)
    public String getComment ()
    {
        return comment;
    }

    public void setComment (String comment)
    {
        this.comment = comment;
    }

    @Column (nullable = false)
    public Date getLastUpdated ()
    {
        return lastUpdated;
    }

    public void setLastUpdated (Date lastUpdated)
    {
        this.lastUpdated = lastUpdated;
    }

    @Column (nullable = false)
    public Date getCreateDate ()
    {
        return createDate;
    }

    public void setCreateDate (Date createDate)
    {
        this.createDate = createDate;
    }

    public Date getShipDate ()
    {
        return shipDate;
    }

    public void setShipDate (Date shipDate)
    {
        this.shipDate = shipDate;
    }

    public String getLogisticsNumber ()
    {
        return logisticsNumber;
    }

    public void setLogisticsNumber (String logisticsNumber)
    {
        this.logisticsNumber = logisticsNumber;
    }

    public boolean isInvoiced ()
    {
        return isInvoiced;
    }

    public void setInvoiced (boolean isInvoiced)
    {
        this.isInvoiced = isInvoiced;
    }

    public boolean isShipped ()
    {
        return isShipped;
    }

    public void setShipped (boolean isShipped)
    {
        this.isShipped = isShipped;
    }

    public String getNetworkOrderId ()
    {
        return networkOrderId;
    }

    public void setNetworkOrderId (String networkOrderId)
    {
        this.networkOrderId = networkOrderId;
    }

    @Column (nullable = false)
    public OrderStatusCode getStatusCode ()
    {
        return statusCode;
    }

    public void setStatusCode (OrderStatusCode statusCode)
    {
        this.statusCode = statusCode;
    }

    @Column (nullable = false)
    public OrderTypeCode getTypeCode ()
    {
        return typeCode;
    }

    public void setTypeCode (OrderTypeCode typeCode)
    {
        this.typeCode = typeCode;
    }

    @ManyToOne
    @JoinColumn (name = "customer_id")
    public Customer getCustomer ()
    {
        return customer;
    }

    public void setCustomer (Customer customer)
    {
        this.customer = customer;
    }

    public float getDiscount ()
    {
        return discount;
    }

    public void setDiscount (float discount)
    {
        this.discount = discount;
    }

    public float getReceivable ()
    {
        return receivable;
    }

    public void setReceivable (float receivable)
    {
        this.receivable = receivable;
    }

    public long getProject ()
    {
        return project;
    }

    public void setProject (long project)
    {
        this.project = project;
    }

    @ManyToOne
    @JoinColumn (name = "contact_id")
    public Contact getContact ()
    {
        return contact;
    }

    public void setContact (Contact contact)
    {
        this.contact = contact;
    }

    public long getUserCreatedBy ()
    {
        return userCreatedBy;
    }

    public void setUserCreatedBy (long userCreatedBy)
    {
        this.userCreatedBy = userCreatedBy;
    }

    public long getUserUpdatedBy ()
    {
        return userUpdatedBy;
    }

    public void setUserUpdatedBy (long userUpdatedBy)
    {
        this.userUpdatedBy = userUpdatedBy;
    }

    public long getUserOperatedBy ()
    {
        return userOperatedBy;
    }

    public void setUserOperatedBy (long userOperatedBy)
    {
        this.userOperatedBy = userOperatedBy;
    }

    @ManyToOne
    @JoinColumn (name = "receiver_id")
    public Receiver getReceiver ()
    {
        return receiver;
    }

    public void setReceiver (Receiver receiver)
    {
        this.receiver = receiver;
    }

}
